﻿using Game.Actions;
using Game.Ai.Internal.States;
using Game.Common;
using Game.Level;
using Game.Map;
using Game.Objects;
using Game.StateMachine;

namespace Game.Ai.Internal
{
    class StateMachineAiContoller : AiController
    {
        readonly Machine _machine;
        
        public StateMachineAiContoller(
            Vehicle vehicle, 
            IGameMapView map,
            GameLevels levels,
            ActionExecutor executor,
            GameTurn turn)
            : base(vehicle, map, levels, turn)
        {
            var ext = vehicle.Extensions.Find<AiExtension>();
            if (ext == null)
            {
                _machine = new AttackMachine(executor);
            }
            else if (ext.AiBehavoir == AiBehavoirEnum.Attack)
            {
                _machine = new AttackMachine(executor);
            }
            else
            {
                _machine = new PatrolMachine(executor);
            }
        }
        
        public override void DoTurn()
        {
            _machine.DoTurn(GameMapView, GameLevels, this, GameTurn);
        }
        
    }
}
